﻿namespace WebHome_API.Models.DBModels
{
    public class AdminLog_Table
    {
        public int ID { get; set; }
        public int UserId { get; set; }
        public string Log { get; set; }
        public DateTime CreateTime { get; set; }



        public static AdminLog_Table CreateLog<T>(LogStateEnum logState, int userId, T data)
        {
            switch (logState)
            {
                case LogStateEnum.delGal:
                    return new AdminLog_Table()
                    {
                        UserId = userId,
                        CreateTime = DateTime.Now,
                        Log = _delGal_StateLog((data as string)!),
                    };
                case LogStateEnum.AddGal:
                    return new AdminLog_Table()
                    {
                        UserId = userId,
                        CreateTime = DateTime.Now,
                        Log = _addGal_StateLog((data as string)!),
                    };
                case LogStateEnum.AddFileOfGal:
                    return new AdminLog_Table()
                    {
                        UserId = userId,
                        CreateTime = DateTime.Now,
                        Log = _AddFileOfGal_StateLog((data as string)!),
                    };
                case LogStateEnum.AddGalTag:
                    return new AdminLog_Table()
                    {
                        UserId = userId,
                        CreateTime = DateTime.Now,
                        Log = _AddGalTag_StateLog((data as string)!),
                    };
                case LogStateEnum.DelGalTag:
                    return new AdminLog_Table()
                    {
                        UserId = userId,
                        CreateTime = DateTime.Now,
                        Log = _DelGalTag_StateLog((data as string)!),
                    };
                default:
                    return null;
            }
        }


        private static string _DelGalTag_StateLog(string data)
        {
            var arr = data.Split(',');
            return $"向Gal:[{arr[0]}]删除了Tag:[{arr[1]}]";
        }
        private static string _AddGalTag_StateLog(string data)
        {
            var arr = data.Split(',');
            return $"向Gal:[{arr[0]}]添加了Tag:[{arr[1]}]";
        }
        private static string _AddFileOfGal_StateLog(string data)
        {
            return $"添加了FileId:[{data}]的File数据";
        }
        private static string _addGal_StateLog(string data)
        {
            return $"添加了ID:[{data}]的Gal数据";
        }
        private static string _delGal_StateLog(string data)
        {
            return $"删除了ID:[{data}]的Gal数据";
        }
    }

    public enum LogStateEnum
    {
        delGal,
        AddGal,
        AddFileOfGal,
        AddGalTag,
        DelGalTag,
    }
}
